package com.weetop.cfw.base.presenter.imp

import com.blankj.utilcode.util.LogUtils
import com.weetop.cfw.base.presenter.AudioDetailPresenter
import com.weetop.cfw.base.view.AudioDetailView
import com.weetop.cfw.base.view.BaseView
import com.weetop.cfw.bean.AudioVideoDetailBean
import com.weetop.cfw.bean.ErrorBean
import com.weetop.cfw.bean.RecommendAudioVideoBean
import com.weetop.cfw.callback.RxJavaCallBack
import com.weetop.cfw.mine.activity.AudioDetailActivity
import com.weetop.cfw.utils.RetrofitUtils
import com.weetop.cfw.utils.RxJavaUtils

class AudioDetailPresenterImp(var audioDetailView: AudioDetailView? = null):AudioDetailPresenter {

    /**
     * 上传管理音频浏览记录
     */
    override fun uploadUserAudioAndVideoBrowsingRecords(audioDetailActivity:AudioDetailActivity, infoid: String) {
        RxJavaUtils.useInAppCompatActivityOnDestory(RetrofitUtils.getApi().uploadUserAudioAndVideoBrowsingRecordsData(infoid = infoid),audioDetailActivity,object:RxJavaCallBack<ErrorBean>(){
            override fun onSuccess(t: ErrorBean?) {
                if(t != null){
                    LogUtils.dTag("上传管理音频浏览记录",t.message)
                }
            }

            override fun onRequestError(t: ErrorBean?) {
                super.onRequestError(t)
                if(t != null){
                    LogUtils.dTag("上传管理音频浏览记录",t.message)
                }
            }

        })
    }

    /**
     * 获取音频详情数据
     */
    override fun getAudioDetailData(audioDetailActivity:AudioDetailActivity,infoid:Int) {
        audioDetailActivity.showLoadingDialog(audioDetailActivity,"正在获取商业音频数据...")
        RxJavaUtils.useInAppCompatActivityOnDestory(RetrofitUtils.getApi().getAudioFrequencyDetail(infoid),audioDetailActivity,object:RxJavaCallBack<AudioVideoDetailBean>(){
            override fun onSuccess(t: AudioVideoDetailBean?) {
                audioDetailActivity.dismissLoadingDialog()
                audioDetailView?.audioDetailDataGetSuccess(t)
            }

            override fun onErrorResponse(throwable: Throwable?) {
                super.onErrorResponse(throwable)
                audioDetailActivity.dismissLoadingDialog()
            }

            override fun onRequestError(t: AudioVideoDetailBean?) {
                super.onRequestError(t)
                audioDetailActivity.dismissLoadingDialog()
            }

        })
    }


    /**
     * 绑定
     */
    override fun attachView(baseView: BaseView) {
        audioDetailView = baseView as? AudioDetailView
    }

    /**
     * 解绑
     */
    override fun detachView() {
        audioDetailView = null
    }
}